package de.fuberlin.inf.alp3.ue03;

public class A implements ValueReader.Readable {
    String s;

    public A(int indent) {
        fromConsole(indent);
    }

    public String toString() {
        return this.toString(0);
    }
    public String toString(int indent) {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < (indent * ValueReader.INDENT); i++)
            sb.append(' ');
        sb.append("A-Objekt:\n");
        for (int i = 0; i < (indent * ValueReader.INDENT); i++)
            sb.append(' ');
        sb.append("String s: ");
        if (this.s == null)
            sb.append("<null>");
        else if (this.s.equals(""))
            sb.append("<empty>");
        else
            sb.append(this.s);
        sb.append('\n');
        return sb.toString();
    }

    @Override
    public void fromConsole(int indent) {
        for (int i = 0; i < (indent * ValueReader.INDENT); i++)
            System.out.print(' ');
        System.out.println("A-Objekt lesen:");
        while (true) {
            String input = ValueReader.readString((indent),
                    "String s (new/null?)");
            if (input.equals("null")) {
                this.s = null;
                break;
            }
            if (input.equals("new")) {
                this.s = ValueReader.readString(indent, "String");
                break;
            }
        }
    }
}
